home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Snippets / Nets & Comm / testNBP / testNBP.c next >
Encoding:
C/C++ Source or Header  |  1991-10-21  |  6.8 KB  |  239 lines  |  [TEXT/MPS ]

  1. /*
  2.  *  Test program to demonstrate case insensitivity of NBP
  3.  *    two names are registered and confirmed.  A lookup is performed with both lower case and 
  4.  *    upper case inital letters of the object.
  5.  *    Use a debugger statement to halt program execution while a network tool is used to 
  6.  *    examine entities registered to the netwrok.
  7.  * Also useful for demonstrating the use of the PSetSelfSend capability.
  8.  */
  9.  
  10. /* Use the following instructions to build this programm assuming this file is named 'testnbp.c'
  11.  
  12. C -r 'testNBP.c'
  13. Link -d -c '????' -t APPL ∂
  14.     'testNBP.c.o' ∂
  15.     "{CLibraries}"StdClib.o ∂
  16.     "{MPW}"Libraries:Libraries:SIOW.o ∂
  17.     "{Libraries}"Runtime.o ∂
  18.     "{Libraries}"Interface.o ∂
  19.     -o testnbp
  20. Rez -a "{MPW}"Interfaces:Rincludes:SIOW.r -o testnbp
  21.  
  22. */
  23.  
  24.  
  25. #if !defined(USEDUMP)
  26.     #include <Types.h>
  27.     #include <OSUtils.h>
  28.     #include <Appletalk.h>
  29.     #include <Memory.h>
  30.     #include <Strings.h>
  31.     #include <String.h>
  32.     #include <stdio.h>
  33.     #include <Events.h>
  34.     #include <StdLib.h>
  35.     #if defined(MAKEDUMP)
  36.         #pragma dump "nbpDumpFile"
  37.     #endif
  38. #else
  39.     #pragma load "nbpDumpFile"
  40. #endif
  41.  
  42.  
  43. #include <Types.h>
  44. #include <OSUtils.h>
  45. #include <Appletalk.h>
  46. #include <Memory.h>
  47. #include <Strings.h>
  48. #include <String.h>
  49. #include <stdio.h>
  50. #include <Events.h>
  51. #include <StdLib.h>
  52.  
  53.  
  54. OSErr                result;
  55. ATPParamBlock        my_atp;
  56. MPPParamBlock        my_nbp,self;
  57. NamesTableEntry        entity1, entity2, entity3;
  58. char                tempBuffer[2048];
  59. short                input;
  60. char                *nbpObject, *nbpType, *nbpZone;
  61. char                newSocket;
  62. short                tempNode;
  63. char                saveSelfState;
  64.  
  65. main()
  66. {
  67.     if (MPPOpen() != noErr)    {
  68.         printf("Error opening MPP - Aborting program!\n");
  69.         fflush(stdout);
  70.         exit(-1);
  71.     }
  72.     
  73.     if (ATPLoad() != noErr) {
  74.         printf("Error opening ATP - Aborting program!\n");
  75.         fflush(stdout);
  76.         exit(-1);
  77.     }
  78.     
  79. /* open a socket */
  80.     my_atp.ATP.atpSocket = 0;
  81.     my_atp.ATP.addrBlock.aNet = 0;
  82.     my_atp.ATP.addrBlock.aNode = 0;
  83.     my_atp.ATP.addrBlock.aSocket = 0;
  84.     result = POpenATPSkt(&my_atp, false);
  85.     printf("Result of opening socket was %d.\n", result);
  86.     printf("atpSocket is %u.\n", (unsigned char) my_atp.ATP.atpSocket);
  87.     
  88. /* Get the current node address info for PConfirmName */
  89.     GetNodeAddress(&tempNode, (short *) &my_atp.ATP.addrBlock.aNet);
  90.     my_atp.ATP.addrBlock.aNode = tempNode;
  91.     my_atp.ATP.addrBlock.aSocket = my_atp.ATP.atpSocket;
  92.     
  93.     printf("addrBlock.aNet is %d.\n", my_atp.ATP.addrBlock.aNet);
  94.     printf("addrBlock.aNode is %d.\n", my_atp.ATP.addrBlock.aNode);
  95.     printf("addrBlock.aSocket is %d.\n\n", my_atp.ATP.addrBlock.aSocket);
  96.     fflush(stdout);
  97.         
  98.     if (result != noErr)    {
  99.     
  100.         printf("Error opening socket - Aborting program!\n");
  101.         fflush(stdout);
  102.         exit(-1);
  103.     }
  104.     
  105. /* set selfsend so that we can see ourselves */
  106.     printf("Setting Self Send state to true.\n");
  107.     self.SETSELF.newSelfFlag = 1;
  108.     PSetSelfSend(&self, false);
  109.     saveSelfState = self.SETSELF.oldSelfFlag;
  110.     
  111.     if (saveSelfState)
  112.         printf("Old Self send state was true.\n");
  113.     else
  114.         printf("Old Self send state was false.\n\n");
  115.         
  116.     
  117.  
  118. /* register first item with upper case initial letters */
  119.     nbpObject = "\pa";
  120.     nbpType = "\pComputer Server";
  121.     nbpZone = "\p*";
  122.     
  123.     
  124.     NBPSetNTE ((Ptr) &entity1, (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone, my_atp.ATP.atpSocket);
  125.     my_nbp.NBP.NBPPtrs.ntQElPtr = (Ptr) &entity1;
  126.     my_nbp.NBP.interval = 4;
  127.     my_nbp.NBP.count = 2;
  128.     my_nbp.NBP.parm.verifyFlag = true;
  129.  
  130.     result = PRegisterName(&my_nbp, false);
  131.  
  132.     printf("Result of first register was %d.\n", result);
  133.     printf("ioResult returned %d.\n", my_nbp.NBP.ioResult);
  134.     
  135.     fflush(stdout);
  136.  
  137. /* Confirm first name */
  138.     NBPSetEntity ((Ptr) &entity1.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
  139.     my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity1.nt.entityData[0];
  140.     my_nbp.NBP.interval = 4;
  141.     my_nbp.NBP.count = 3;
  142.     BlockMove ((Ptr) &my_atp.ATP.addrBlock, (Ptr) &my_nbp.NBP.parm.Confirm.confirmAddr, sizeof(AddrBlock));
  143.  
  144.     result = PConfirmName(&my_nbp, false);
  145.  
  146.     printf("Result of first confirm was %d.\n", result);
  147.     printf("ioResult returned %d.\n\n", my_nbp.NBP.ioResult);
  148.     fflush(stdout);
  149.  
  150. /* Register second name with lower case initial letters */    
  151.     nbpObject = "\pb";
  152.     nbpType = "\pcomputer server";
  153.  
  154.     NBPSetNTE ((Ptr) &entity2, (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone, my_atp.ATP.atpSocket);
  155.     my_nbp.NBP.NBPPtrs.ntQElPtr = (Ptr) &entity2;
  156.     my_nbp.NBP.interval = 8;
  157.     my_nbp.NBP.count = 3;
  158.     my_nbp.NBP.parm.verifyFlag = true;
  159.  
  160.     result = PRegisterName(&my_nbp, false);
  161.  
  162.     printf("Result of second register was %d.\n", result);
  163.     printf("ioResult returned %d.\n", my_nbp.NBP.ioResult);
  164.     fflush(stdout);
  165.  
  166. /* Confirm second name */
  167.     NBPSetEntity ((Ptr) &entity2.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
  168.     my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity2.nt.entityData[0];
  169.     my_nbp.NBP.interval = 8;
  170.     my_nbp.NBP.count = 3;
  171.     BlockMove ((Ptr) &my_atp.ATP.addrBlock, (Ptr) &my_nbp.NBP.parm.Confirm.confirmAddr, sizeof(AddrBlock));
  172.  
  173.     result = PConfirmName(&my_nbp, false);
  174.  
  175.     printf("Result of second confirm was %d.\n", result);
  176.     printf("ioResult returned %d.\n\n", my_nbp.NBP.ioResult);
  177.     fflush(stdout);
  178.  
  179.  
  180. /* lookup with lower case name */
  181.     nbpObject = "\p=";
  182. /*    nbpObject = "\p≈"; */
  183.     nbpType = "\pcomputer server";
  184.     
  185.     NBPSetEntity ((Ptr) &entity3.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
  186.     my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity3.nt.entityData[0];
  187.     my_nbp.NBP.interval = 4;
  188.     my_nbp.NBP.count = 3;
  189.     my_nbp.NBP.parm.Lookup.retBuffPtr = &tempBuffer;
  190.     my_nbp.NBP.parm.Lookup.retBuffSize = 2048;
  191.     my_nbp.NBP.parm.Lookup.maxToGet = 20;
  192.  
  193.     result = PLookupName(&my_nbp, false);
  194.  
  195.     printf("Result of lower case lookup was %d.\n", result);
  196.     printf("ioResult was %d.\n", my_nbp.NBP.ioResult);
  197.     printf("NumGotten was %d.\n\n", my_nbp.NBP.parm.Lookup.numGotten);
  198.     fflush(stdout);
  199.     
  200. /* lookup with upper case name */
  201.     nbpType = "\pComputer Server";
  202.     
  203.     NBPSetEntity ((Ptr) &entity3.nt.entityData[0], (Ptr)nbpObject, (Ptr)nbpType, (Ptr)nbpZone);
  204.     my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity3.nt.entityData[0];
  205.     my_nbp.NBP.interval = 4;
  206.     my_nbp.NBP.count = 3;
  207.     my_nbp.NBP.parm.Lookup.retBuffPtr = &tempBuffer;
  208.     my_nbp.NBP.parm.Lookup.retBuffSize = 2048;
  209.     my_nbp.NBP.parm.Lookup.maxToGet = 20;
  210.  
  211.     result = PLookupName(&my_nbp, false);
  212.     
  213.     printf("Result of upper case lookup was %d.\n", result);
  214.     printf("ioResult was %d.\n", my_nbp.NBP.ioResult);
  215.     printf("NumGotten was %d.\n\n", my_nbp.NBP.parm.Lookup.numGotten);
  216.     fflush(stdout);
  217.  
  218. /* Restore self send state */    
  219.     self.SETSELF.newSelfFlag = saveSelfState;
  220.     PSetSelfSend(&self, false);
  221.     saveSelfState = self.SETSELF.oldSelfFlag;
  222.  
  223.     
  224. /* Remove names */
  225.     my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity1.nt.entityData[0];
  226.     result = PRemoveName(&my_nbp, false);
  227.     printf("Result of removing entity1 was %d.\n", result);
  228.  
  229.     my_nbp.NBP.NBPPtrs.entityPtr = (Ptr) &entity2.nt.entityData[0];
  230.  
  231.     result = PRemoveName(&my_nbp, false);
  232.     printf("Result of removing entity2 was %d.\n", result);
  233.     
  234.     result = PCloseATPSkt(&my_atp, false);
  235.     printf("Result of closing socket was %d.\n", result);
  236.     fflush(stdout);
  237.     ATPUnload();
  238. }
  239.